package com.geen.tuoke.network.interceptor

import com.seeway.wms.network.utils.ApiSignUtils
import com.seeway.wms.network.utils.ApiSignUtils.buildSign
import com.geen.tuoke.network.utils.CacheUtil
import com.geen.tuoke.utils.KVConstants
import com.tencent.mmkv.MMKV
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

/***
 * @author 86153
 * 请求参数拦截器
 */
class ParameterInterceptor : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val original = chain.request()
        val originalHttpUrl = original.url()
        val authTime = System.currentTimeMillis().toString()
        val sign = buildSign(authTime)
        val token = MMKV.defaultMMKV().getString(KVConstants.TOKEN, "")
        val url = originalHttpUrl.newBuilder()
            //.addQueryParameter("token", token)
            .build()
        val requestBuilder = original.newBuilder()
            .url(url)
            .method(original.method(), original.body())
        val request = requestBuilder.build()
        return chain.proceed(request)
    }
}